package com.galaxy.user.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.galaxy.common.core.domain.R;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.user.domain.UserFeedback;
import com.galaxy.user.domain.bo.UserFeedbackBo;
import com.galaxy.user.domain.vo.UserFeedbackVo;
import com.galaxy.user.service.UserFeedbackService;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户反馈Controller
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/feedback")
public class UserFeedbackApiController {

    private final UserFeedbackService userFeedbackService;
    private final Converter converter;

    /**
     * 查询用户反馈列表
     */
    @GetMapping("/list")
    public TableDataInfo<UserFeedbackVo> list(UserFeedbackBo bo, PageQuery pageQuery) {
        return userFeedbackService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取用户反馈详细信息
     */
    @GetMapping("/{id}")
    public R<UserFeedbackVo> getInfo(@PathVariable Long id) {
        UserFeedback feedback = userFeedbackService.queryById(id);
        return R.ok(converter.convert(feedback, UserFeedbackVo.class));
    }

    /**
     * 新增用户反馈
     */
    @PostMapping
    public R<Boolean> add(@Validated @RequestBody UserFeedbackBo bo) {
        return R.ok(userFeedbackService.insertByBo(bo));
    }

    /**
     * 修改用户反馈
     */
    @PutMapping
    public R<Boolean> edit(@Validated @RequestBody UserFeedbackBo bo) {
        return R.ok(userFeedbackService.updateByBo(bo));
    }

    /**
     * 删除用户反馈
     */
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable List<Long> ids) {
        return R.ok(userFeedbackService.deleteWithValidByIds(ids, true));
    }

    @PutMapping("/updateByDeviceId")
    public R<Boolean> updateByDeviceId(@RequestBody UserFeedbackBo bo) {
        return R.ok(userFeedbackService.updateByDeviceId(bo));
    }
}
